package cn.hunau.bookstore.filter;

import java.io.IOException;

import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 对编码格式进行处理
 * 
 * @author HuangBo
 *
 *         2022-01-18 16:09:04
 *
 */
@WebFilter(urlPatterns = { "/*" })
public class EncodingFilter extends HttpFilter {
	@Override
	protected void doFilter(HttpServletRequest request, HttpServletResponse response, FilterChain chain)
			throws IOException, ServletException {
		String servletPath = request.getServletPath();
		if (servletPath.contains(".css") || servletPath.contains(".js") || servletPath.contains(".png")
				|| servletPath.contains(".jpg")) {
			chain.doFilter(request, response);
			return;
		} else {
			request.setCharacterEncoding("utf-8");
			response.setContentType("text/html;charset=utf-8");
			chain.doFilter(request, response);
		}
	}
}
